from tel_manage import *
from ui import *
import sys

mainmenu = [
    "1. 显示所有联系人()", "2. 新建联系人", "3. 查找联系人", "4. 编辑联系人", "4. 删除联系人",
    "5. 查找重复联系人", "6. 保存所有更改", "7. 帮助", "8. 退出"
]
commands = [
    "list", "new", "search", "edit", "del", "deduplication", "save", "help",
    "exit"
]
header = ["序号", "姓名", "电话号码", "住址"]
ui = Ui()
tel_data = TelData()
command = ui.get_command(commands)
while (True):
    if command[0] == "help":
        ui.show_menu(mainmenu, commands)
    elif command[0] == "list":
        ui.show_tel_header(header)
        ui.show_tel_book(tel_data.tel_book)
    elif command[0] == "new":
        tel_data.new(ui.new())
    elif command[0] == "search":
        ui.show_tel_header(header)
        ui.show_tel_book(tel_data.search(command[1]))
    elif command[0] == "edit":
        ui.edit(ui.choose_operate_object(tel_data, header))
    elif command[0] == "del":
        ui.delete(tel_data.tel_book,
                  ui.choose_operate_object(tel_data, header))
    elif command[0] == "deduplication":
        pass
    elif command[0] == "save":
        tel_data.save_tel_book()
    elif command[0] == "exit":
        if (ui.confirm_exit()):
            print("谢谢您的使用，再见！")
            sys.exit()
    command = ui.get_command(commands)